<template>
  <div class="historyBox">
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <div class="cus-card" v-for="(item, index) in list" :key="index" @click="goDetail(item.id)">
        <div class="card-top">
          <div class="fjh">{{ item.roomName }}</div>
          <div class="zt" :class="item.status == '0' ? 'zt0' : 'zt2'">{{ judgeZt(item.status, deptName) }}</div>
        </div>
        <div class="sj">{{ item.createdTime }}</div>
        <div class="yj">
          <div class="title">意见建议</div>
          <div class="content">{{ item.eventContent }}</div>
        </div>
      </div>
    </van-list>
  </div>
</template>

<script>
import { mapGetters } from 'vuex';
import { appEventList, eventList } from '@/api/info';
export default {
  name: 'historyBox',
  data() {
    return {
      role: window.localStorage.getItem('role'),
      list: [],
      loading: false,
      finished: false,
      params: {
        pageNum: 1,
        pageSize: 10,
      },
      total: 0
    }
  },
  computed: {
    ...mapGetters(['deptName'])
  },
  mounted() {
    if(['游客', '业主'].indexOf(this.deptName) !== -1) {
      this.appEventList()
    } else {
      this.eventList()
    }
  },
  methods: {
    onLoad() {
      if(this.total > this.params.pageNum * this.params.pageSize) {
        if(['游客', '业主'].indexOf(this.deptName) !== -1) {
          this.appEventList()
        } else {
          this.eventList()
        }
      }
      this.loading = false
      this.finished = true
    },
    judgeZt(val, deptName) {
      if(val == '0') {
          return '处理完毕'
        } else {
          return '待处理'
        }
      /* if(deptName == '协会') {
        if(val == '1') {
          return '待处理'
        } else if(val == '2') {
          return '已流转'
        } else if(val == '3') {
          return '退回'
        } else if(val == '0') {
          return '处理完毕'
        }
      } else {
        if(val == '0') {
          return '处理完毕'
        } else {
          return '待处理'
        }
      } */
    },
    appEventList() {
      appEventList(this.params).then(res => {
        if(res.code == 200) {
          this.list = res.rows;
          this.total = res.total;
        }
      })
    },
    eventList() {
      eventList(this.params).then(res => {
        if(res.code == 200) {
          this.list = res.rows;
          this.total = res.total;
        }
      })
    },
    goDetail(id) {
      this.$router.push('/yjjy-detail?id=' + id)
    }
  }
}
</script>

<style lang="less" scoped>
.historyBox {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  .cus-card {
    background-color: #fff;
    margin: 0 16px;
    margin-top: 12px;
    border-radius: 9px;
    padding: 16px;
    box-sizing: border-box;
    cursor: pointer;
    .card-top {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      .fjh {
        color: #333333;
        font-family: PingFang SC;
        font-weight: medium;
        font-size: 18px;
        letter-spacing: 0px;
        text-align: left;
      }
      .zt {
        border-radius: 2px;
        font-family: PingFang SC;
        font-weight: regular;
        font-size: 11px;
        letter-spacing: 0px;
        text-align: center;
        padding: 2px 4px;
        border: 0.5px solid #FF8F1F;
        color: #FF8F1F;
        width: 50px;
        line-height: 1.5;
        margin-top: 3px;
        &.zt0 {
          border: 0.5px solid #00B578;
          color: #00B578;
        }
        &.zt2 {
          border: 0.5px solid #31d5e3;
          color: #31d5e3;
        }
        &.zt3 {
          border: 0.5px solid #ca4747;
          color: #ca4747;
        }
      }
    }
    .sj {
      color: #999999;
      font-family: PingFang SC;
      font-weight: regular;
      font-size: 12px;
      line-height: 20px;
      letter-spacing: 0px;
      text-align: left;
      margin-bottom: 4px;
    }
    .yj {
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
      .title {
        color: #333333;
        font-size: 13px;
        letter-spacing: 0px;
        text-align: left;
        width: 100px;
      }
      .content {
        color: #666666;
        font-size: 13px;
        letter-spacing: 0px;
        text-align: left;
      }
    }
  }
}
</style>